﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using MM.Commmon.UI.Controls;
using MM.Common.UI.Controls;
using MM.Common.DBBase;
using MM.Common.Base;
using MM.Commmon.UI.Properties;

namespace MM.Commmon.UI
{
    public partial class FrmAlert : XtraForm
    {
        public FrmAlert()
        {
            InitializeComponent();
        }

        public FrmAlert(Exception ex)
        {
            InitializeComponent();
            picAlert.Image = Resources.error88;
            panelControl1.Visible = true;
            btnOK.Focus();
            ucMemoSuggestion.Text = ex.StackTrace;
            ucLabelName.Text = ex.Message;
            this.Text = "未知错误";
        }

        public FrmAlert(string infoDetailCode)
        {
            this.InitializeComponent();
            if (SystemInfo.DbData.IsOpen)
            {
                DataTable dt = new DataTable();
                DataParamCol parm = new DataParamCol(new DataParam[] { new InputDataParam("dtcode", infoDetailCode) });
                string commandtext = "SELECT \r\nDETAIL.INFO_CODE INFO_CODE,\r\nDETAIL.INFO_DETAIL_CODE INFO_DETAIL_CODE, \r\nDETAIL.FORM_CODE FORM_CODE,\r\nDETAIL.SUGGESTION DETAILSUGGESTION,\r\nCATALOG.SUGGESTION CATALOGSUGGESTION,\r\nCATALOG.INFO_NAME INFO_NAME,\r\nCATALOG.BUTTONTYPE BUTTONTYPE\r\nFROM MXHLY_SYS_INFO_DETAIL DETAIL,MXHLY_SYS_INFO_CATALOG CATALOG\r\nWHERE DETAIL.INFO_CODE=CATALOG.INFO_CODE AND DETAIL.INFO_DETAIL_CODE=:DTCODE";
                SystemInfo.DbData.Retrieve(commandtext, parm, ref dt);
                if (dt.Rows.Count == 1)
                {
                    string str2 = dt.Rows[0]["INFO_CODE"].ToString().Trim();
                    dt.Rows[0]["INFO_DETAIL_CODE"].ToString().Trim();
                    dt.Rows[0]["FORM_CODE"].ToString().Trim();
                    string str3 = dt.Rows[0]["detailSUGGESTION"].ToString().Trim();
                    string str4 = dt.Rows[0]["catalogSUGGESTION"].ToString().Trim();
                    string str5 = dt.Rows[0]["INFO_NAME"].ToString().Trim();
                    string str6 = dt.Rows[0]["BUTTONTYPE"].ToString().Trim();
                    if (string.IsNullOrEmpty(str4))
                    {
                        ucMemoSuggestion.Text = str3;
                    }
                    else
                    {
                        ucMemoSuggestion.Text = str4;
                    }
                    ucLabelName.Text = str5;
                    string str7 = "";
                    string str8 = str2.Substring(0, 1);
                    if (str8 != null)
                    {
                        if (!(str8 == "S"))
                        {
                            if (str8 == "E")
                            {
                                str7 = "错误";
                                picAlert.Image = Resources.error88;
                            }
                            else if (str8 == "I")
                            {
                                str7 = "提醒";
                                picAlert.Image = Resources.alert88;
                            }
                            else if (str8 == "Q")
                            {
                                str7 = "选择";
                                picAlert.Image = Resources.qustion88;
                            }
                        }
                        else
                        {
                            str7 = "成功";
                            picAlert.Image = Resources.yes88;
                        }
                    }
                    string str9 = str2.Substring(1, 1);
                    if (str9 != null)
                    {
                        if (!(str9 == "D"))
                        {
                            if (str9 == "S")
                            {
                                str7 = str7 + "-软件";
                            }
                            else if (str9 == "B")
                            {
                                str7 = str7 + "-业务";
                            }
                            else if (str9 == "N")
                            {
                                str7 = str7 + "-网络";
                            }
                            else if (str9 == "O")
                            {
                                str7 = str7 + "-其他";
                            }
                        }
                        else
                        {
                            str7 = str7 + "-数据库";
                        }
                    }
                    this.Text = str7;
                    string str10 = str6;
                    if (str10 != null)
                    {
                        if (!(str10 == "1"))
                        {
                            if (!(str10 == "2"))
                            {
                                if (str10 == "3")
                                {
                                    panelControl3.Visible = true;
                                    btnAbort.Focus();
                                }
                                return;
                            }
                        }
                        else
                        {
                            this.panelControl1.Visible = true;
                            btnOK.Focus();
                            return;
                        }
                        panelControl2.Visible = true;
                        btnYes.Focus();
                    }
                }
            }
        }

        private void btnAbort_Click(object sender, EventArgs e)
        {
            base.DialogResult = DialogResult.Abort;
        }

        private void btnIgnore_Click(object sender, EventArgs e)
        {
            base.DialogResult = DialogResult.Ignore;
        }

        private void btnRetry_Click(object sender, EventArgs e)
        {
            base.DialogResult = DialogResult.Retry;
        }

        private void btnYes_Click(object sender, EventArgs e)
        {
            base.DialogResult = DialogResult.Yes;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            base.DialogResult = DialogResult.OK;
        }

        private void btnNo_Click(object sender, EventArgs e)
        {
            base.DialogResult = DialogResult.No;
        }

        private void btnExpand_Click(object sender, EventArgs e)
        {
            if (base.Height == 390)
            {
                base.Height = 0x91;
                btnExpand.Image = Resources.downarrow;
            }
            else
            {
                base.Height = 390;
                btnExpand.Image = Resources._1uparrow;
            }
        }
    }
}
